﻿using System.Linq;
using GameKits.Unity.GuiForms;
using GameKits.Unity.GuiForms.Controls;
using GameKits.Unity.GuiForms.Forms;

internal class ShowEffectsForm : Form
{
    private FixedToogle[] pivotToogles = new FixedToogle[9];

    protected override void Initialize()
    {
        this.pivotToogles[0] = new FixedToogle
                        {
                            Text = string.Empty,
                            Position = new Position(5, 5),
                            Size = new Size(15, 15)
                        };

        this.pivotToogles[0].Changed += this.Tootle_Changed;

        this.pivotToogles[1] = new FixedToogle
                        {
                            Text = string.Empty,
                            Position = new Position(191, 5),
                            Size = new Size(15, 15)
                        };

        this.pivotToogles[1].Changed += this.Tootle_Changed;

        this.pivotToogles[2] = new FixedToogle
                        {
                            Text = string.Empty,
                            Position = new Position(380, 5),
                            Size = new Size(15, 15)
                        };

        this.pivotToogles[2].Changed += this.Tootle_Changed;

        this.pivotToogles[3] = new FixedToogle
                        {
                            Text = string.Empty,
                            Position = new Position(5, 133),
                            Size = new Size(15, 15)
                        };

        this.pivotToogles[3].Changed += this.Tootle_Changed;

        this.pivotToogles[4] = new FixedToogle
                        {
                            Text = string.Empty,
                            Position = new Position(191, 133),
                            Size = new Size(15, 15)
                        };

        this.pivotToogles[4].Changed += this.Tootle_Changed;

        this.pivotToogles[5] = new FixedToogle
                        {
                            Text = string.Empty,
                            Position = new Position(380, 133),
                            Size = new Size(15, 15)
                        };

        this.pivotToogles[5].Changed += this.Tootle_Changed;

        this.pivotToogles[6] = new FixedToogle
                        {
                            Text = string.Empty,
                            Position = new Position(5, 280),
                            Size = new Size(15, 15)
                        };

        this.pivotToogles[6].Changed += this.Tootle_Changed;

        this.pivotToogles[7] = new FixedToogle
                        {
                            Text = string.Empty,
                            Position = new Position(191, 280),
                            Size = new Size(15, 15)
                        };

        this.pivotToogles[7].Changed += this.Tootle_Changed;

        this.pivotToogles[8] = new FixedToogle
                        {
                            Text = string.Empty,
                            Position = new Position(380, 280),
                            Size = new Size(15, 15)
                        };

        this.pivotToogles[8].Changed += this.Tootle_Changed;

        this.Add(this.pivotToogles);

        this.WindowRect = CalculatePosition(EffectPivots.MiddleLeft, 400, 300);
        this.Title = "Test Effects";
        this.IsDraggable = true;
    }

    private void Tootle_Changed(object sender, System.EventArgs e)
    {
        var toogle = (FixedToogle)sender;

        if (toogle.Value)
        {
            foreach (var item in this.pivotToogles.Where(item => item != toogle))
            {
                item.Value = false;
            }
        }
    }
}
